/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jCoordinatesDialog.java
 *
 * Created on 2009.07.10., 12:47:49
 */
package jtechdig;

import java.awt.Color;

/**
 *
 * @author kipe
 */
public class jCoordinatesDialog extends javax.swing.JDialog {

    /** Creates new form jCoordinatesDialog */
    public jCoordinatesDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        xCoordText = new javax.swing.JTextField();
        yCoordText = new javax.swing.JTextField();
        OKButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setLocationByPlatform(true);
        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jtechdig.JTechDigApp.class).getContext().getResourceMap(jCoordinatesDialog.class);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        xCoordText.setText(resourceMap.getString("xCoordText.text")); // NOI18N
        xCoordText.setName("xCoordText"); // NOI18N
        xCoordText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                xCoordTextActionPerformed(evt);
            }
        });
        xCoordText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                xCoordTextFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                xCoordTextFocusLost(evt);
            }
        });
        xCoordText.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                xCoordTextInputMethodTextChanged(evt);
            }
        });

        yCoordText.setText(resourceMap.getString("yCoordText.text")); // NOI18N
        yCoordText.setName("yCoordText"); // NOI18N
        yCoordText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                yCoordTextFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                yCoordTextFocusLost(evt);
            }
        });
        yCoordText.addInputMethodListener(new java.awt.event.InputMethodListener() {
            public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
            }
            public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
                yCoordTextInputMethodTextChanged(evt);
            }
        });

        OKButton.setText(resourceMap.getString("OKButton.text")); // NOI18N
        OKButton.setName("OKButton"); // NOI18N
        OKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel2)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(xCoordText))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(OKButton)
                                .addComponent(yCoordText, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(xCoordText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(yCoordText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(OKButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
        // TODO add your handling code here:
        boolean xOK = false, yOK = false;
        if (xCoordText.getText().matches("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?")) {
            xx = Double.parseDouble(xCoordText.getText());
            xOK = true;
        } else {
            xCoordText.setForeground(Color.RED);
        }
        if (yCoordText.getText().matches("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?")) {
            yy = Double.parseDouble(yCoordText.getText());
            yOK = true;
        } else {
            yCoordText.setForeground(Color.RED);
        }
        if (xOK && yOK) {
            dispose();
        }

    }//GEN-LAST:event_OKButtonActionPerformed

    private void xCoordTextInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_xCoordTextInputMethodTextChanged
        // TODO add your handling code here:
    }//GEN-LAST:event_xCoordTextInputMethodTextChanged

    private void yCoordTextInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_yCoordTextInputMethodTextChanged
        // TODO add your handling code here:
//        yCoordText.setBackground(new Color(1, 1, 1));
    }//GEN-LAST:event_yCoordTextInputMethodTextChanged

    private void xCoordTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_xCoordTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_xCoordTextActionPerformed

    private void xCoordTextFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_xCoordTextFocusGained
        // TODO add your handling code here:
        xCoordText.setForeground(Color.BLACK);
    }//GEN-LAST:event_xCoordTextFocusGained

    private void yCoordTextFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_yCoordTextFocusGained
        // TODO add your handling code here:
        yCoordText.setForeground(Color.BLACK);

    }//GEN-LAST:event_yCoordTextFocusGained

    private void xCoordTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_xCoordTextFocusLost
        // TODO add your handling code here:
        if (!xCoordText.getText().matches("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?")) {
            xCoordText.setForeground(Color.RED);
        }
    }//GEN-LAST:event_xCoordTextFocusLost

    private void yCoordTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_yCoordTextFocusLost
        // TODO add your handling code here:
        if (!yCoordText.getText().matches("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?")) {
            yCoordText.setForeground(Color.RED);
        }

    }//GEN-LAST:event_yCoordTextFocusLost

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                jCoordinatesDialog dialog = new jCoordinatesDialog(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton OKButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField xCoordText;
    private javax.swing.JTextField yCoordText;
    // End of variables declaration//GEN-END:variables
    private double xx,  yy;

    /**
     * @return the x
     */
    public double getXx() {
        return this.xx;
    }

    /**
     * @param x the x to set
     */
    public void setXx(double x) {
        this.xx = x;
    }

    /**
     * @return the y
     */
    public double getYy() {
        return this.yy;
    }

    /**
     * @param y the y to set
     */
    public void setYy(double y) {
        this.yy = y;
    }
}
